﻿using Assets.Script.Data.EnemyData;
using UnityEngine;

namespace Assets.Script.Human.Enemy
{
    public class EnemyActionManager : MonoBehaviour
    {
        protected EnemyBody enemyBody;
        protected Animator animator;
        protected IAction currentState;
        protected IAction[] actions;
        public int NowIndex = 0;

        /// <summary>
        /// idle,Follow,RangeAtk,MeleeAtk,BeAtk,Move
        /// </summary>
        /// <param name="actions">idle,Follow,RangeAtk,MeleeAtk,BeAtk,Move</param>
        public virtual void Init(IAction[] actions)
        {
            this.actions = actions;
            currentState = actions[0];
            enemyBody = GetComponent<EnemyBody>();
        }


        private void Update()
        {
            currentState.OnUpdate();
        }

        private void FixedUpdate()
        {
            currentState.OnFixedUpdate();
        }

        public void ChangeState(int index,object[] o=null)
        {
            currentState.Interrupt();
            currentState = actions[index];
            currentState.OnEnter(ref o);
            NowIndex = index;
        }


    }
}
